/*
 * Created on 2005-2-28
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.ims.iaa;

/**
 * @author zhufx
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class IaaThread extends Thread {
	//sleep 1 hour
	public static final int LONG_SLEEP = 3600000; 
	private static final int UNSET = -1;
	//current search site depth
	private int m_iDepth = UNSET;
	public IaaThread(Runnable target, String name){
		super(target, name);
	}
	public IaaThread(String name){
		super(name);
	}
	public IaaThread(){
		super();
	}
	public void setDepth(int iDepth){
		m_iDepth = iDepth;
	}
	public String toString(){
		String sRet = "[" + getName();
		if(m_iDepth != UNSET){
			sRet += " depth: " + m_iDepth;
		}
		return sRet + "]";
	}
	public void longSleep(){
		try{
			sleep(LONG_SLEEP);
		}catch(InterruptedException e){}
	}
	/**
	 * @return IaaThread.toString(), if current thread is a instance of IaaThread
	 * 		   "", else 
	 */
	public static String getLogString(){
	    Thread cur = Thread.currentThread();
	    if(cur instanceof IaaThread){
	        return cur.toString();
	    }
	    return "";
	}
	/**
	 * Set the current anlyzed impression depth
	 * if current thread instance of IaaThread,
	 * set it to current thread object, else do nothing.
	 * @param iDepth, the impression depth
	 * @return true, if current is a instance of IaaThread
	 * 		   false, else
	 */
	public static boolean setImpDepth(int iDepth){
	    Thread cur = Thread.currentThread();
	    if(cur instanceof IaaThread){
	        ((IaaThread)cur).setDepth(iDepth);
	        return true;
	    }
	    return false;
	}
}
